//package com.nari.ysphd.view;
//
//import android.app.Activity;
//import android.content.Context;
//import android.graphics.drawable.ColorDrawable;
//import android.text.TextUtils;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup.LayoutParams;
//import android.view.WindowManager;
//import android.widget.AdapterView;
//import android.widget.AdapterView.OnItemSelectedListener;
//import android.widget.ArrayAdapter;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.LinearLayout;
//import android.widget.PopupWindow;
//import android.widget.Spinner;
//import android.widget.SpinnerAdapter;
//import android.widget.Toast;
//
//import com.jeremyfeinstein.utils.AppConstants;
//import com.jeremyfeinstein.utils.ConfigUtil;
//import com.nari.ysphd.R;
//
//import java.util.ArrayList;
//import java.util.List;
//
///*
// * 消息弹框
// */
//public class SettingDialog extends PopupWindow {
//	private View mMenuView;
//	private Activity window;
//	public LinearLayout ll_item;
//	Button btn_joinhome;
//	private EditText server_input;
//	private EditText port_input;
//	private EditText turn_port;
//	private EditText mcu_port;
////	private Socket mSocket;
//	private Spinner resoSpinner;
//
//	@SuppressWarnings("deprecation")
//	public SettingDialog(final Activity context) {
//		super(context);
//		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		mMenuView = inflater.inflate(R.layout.view_settingdialog, null);
//		window = context;
//		server_input = (EditText) mMenuView.findViewById(R.id.server_input);
//		port_input = (EditText) mMenuView.findViewById(R.id.port_input);
//		turn_port = (EditText) mMenuView.findViewById(R.id.turn_port);
//		mcu_port = (EditText) mMenuView.findViewById(R.id.mcu_port);
//		resoSpinner = (Spinner) mMenuView.findViewById(R.id.resolution);
//		//初始化分辨率下拉列表
//		initResolution(context);
//
//		mMenuView.findViewById(R.id.confirm_button).setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				String ip = server_input.getText().toString().trim();
//				String port = port_input.getText().toString().trim();
////				String turnport = turn_port.getText().toString().trim();
////				String mcuport = mcu_port.getText().toString().trim();
//				if(TextUtils.isEmpty(ip)){
//					Toast.makeText(context, "请输入服务地址", Toast.LENGTH_SHORT).show();
//					return;
//				}
//				if(TextUtils.isEmpty(port)){
//					Toast.makeText(context, "请输入服务端口", Toast.LENGTH_SHORT).show();
//					return;
//				}
//				Toast.makeText(context, "设置已完成", Toast.LENGTH_SHORT).show();
//
//				if (!ip.equals(ConfigUtil.getApp().getRemoteUrl()) || !port.equals(ConfigUtil.getApp().getRemotePort())) {
//					ConfigUtil.getApp().setRemoteUrl(ip);
//					ConfigUtil.getApp().setRemotePort(port);
//					ConfigUtil.getApp().setIpChangeFlag(true);
//				}else{
//					ConfigUtil.getApp().setIpChangeFlag(false);
//				}
//
////				ConfigUtil.getApp().setMCUPort(mcuport);
////				ConfigUtil.getApp().setTurnPort(turnport);
//				AppConstants.SERVER_URL = "http://"+ConfigUtil.getApp().getRemoteUrl()+":"+ConfigUtil.getApp().getRemotePort();
////			    AppConstants.turnAddrTCP = "turn:"+ConfigUtil.getApp().getRemoteUrl()+":"+ConfigUtil.getApp().getTurnPort()+"?transport=tcp";
//				dismiss();
//			}
//		});
//
//		mMenuView.findViewById(R.id.cancel_button).setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				dismiss();
//			}
//		});
//
//		server_input.setText(ConfigUtil.getApp().getRemoteUrl());
//		port_input.setText(ConfigUtil.getApp().getRemotePort());
//		turn_port.setText(ConfigUtil.getApp().getTurnPort());
////		mcu_port.setText(ConfigUtil.getApp().getMCUPort());
//		// 设置按钮监听
//		// 设置SelectPicPopupWindow的View
//		this.setContentView(mMenuView);
//		// 设置SelectPicPopupWindow弹出窗体的宽
//		this.setWidth(LayoutParams.MATCH_PARENT);
//		// 设置SelectPicPopupWindow弹出窗体的高
//		this.setHeight(LayoutParams.MATCH_PARENT);
//		// 设置SelectPicPopupWindow弹出窗体可点�?
//		this.setFocusable(true);
//		// 设置SelectPicPopupWindow弹出窗体动画效果
//		this.setAnimationStyle(R.style.PopupAnimation);
//		// 实例化一个ColorDrawable颜色为半透明
//		ColorDrawable dw = new ColorDrawable(window.getResources().getColor(R.color.color_transparent_bg));
//		// 设置SelectPicPopupWindow弹出窗体的背景
//		this.setBackgroundDrawable(dw);
//		// 添加pop窗口关闭事件
//		this.setOnDismissListener(new poponDismissListener());
//		this.setOutsideTouchable(false);
//		// mMenuView添加OnTouchListener监听判断获取触屏位置如果在�?�择框外面则�?毁弹出框
////		mMenuView.setOnTouchListener(new OnTouchListener() {
////			@SuppressLint("ClickableViewAccessibility")
////			public boolean onTouch(View v, MotionEvent event) {
////
////				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
////				int heightmin = mMenuView.findViewById(R.id.pop_layout).getBottom();
////				int y = (int) event.getY();
////				if (event.getAction() == MotionEvent.ACTION_UP) {
////					if (y < height) {
////						dismiss();
////					}
////					if (y > heightmin) {
////						dismiss();
////					}
////				}
////				return true;
////			}
////		});
//
//
//	}
//
//	private void initResolution(final Activity context) {
//		List<String> list = new ArrayList<String>();
////		list.add("1920x1080");
////		list.add("1280x720");
////		list.add("1024x768");
////		list.add("1024x576");
////		list.add("750x540");
////		list.add("750x420");
////		list.add("640x480");
////		list.add("640x360");
////		list.add("480x360");
////		list.add("480x270");
////		list.add("360x240");
////		list.add("320x240");
////		list.add("180x120");
////		list.add("180x100");
//		list.add("高清(720)");  //1280x720
//		list.add("标清(640)");  //640x480
//		list.add("流畅(180)");  //180x120
//
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
//				android.R.layout.simple_spinner_item, list);
//		adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
//		resoSpinner.setAdapter(adapter);
//		SpinnerAdapter apsAdapter = resoSpinner.getAdapter(); // 得到SpinnerAdapter对象
//		int k = apsAdapter.getCount();
//		for (int i = 0; i < k; i++) {
//			if (ConfigUtil.getApp().getResolution()
//					.equals(apsAdapter.getItem(i).toString())) {
//				resoSpinner.setSelection(i, true);// 默认选中项
//				break;
//			}
//		}
//		resoSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
//			// parent： 为控件Spinner com.aspsine.swipetoloadlayout.view：显示文字的TextView position：下拉选项的位置从0开始
//			@SuppressWarnings("unchecked")
//			public void onItemSelected(AdapterView<?> parent, View view,
//					int position, long id) {
//				// 获取Spinner控件的适配器
//				ArrayAdapter<String> adapter = (ArrayAdapter<String>) parent
//						.getAdapter();
//				ConfigUtil.getApp().setResolution(
//						adapter.getItem(position));
//				resoSpinner.setSelection(position);
//			}
//
//			// 没有选中时的处理
//			public void onNothingSelected(AdapterView<?> parent) {
//				Toast.makeText(context, "请选分辨率", Toast.LENGTH_SHORT).show();
//			}
//		});
//	}
//
//	/**
//	 * 弹出的popWin关闭的事件，主要是为了将背景透明度改回来
//	 *
//	 * @author cg
//	 *
//	 */
//	class poponDismissListener implements PopupWindow.OnDismissListener {
//
//		@Override
//		public void onDismiss() {
//			WindowManager.LayoutParams params = window.getWindow().getAttributes();
//			params.alpha = 1f;
//			window.getWindow().setAttributes(params);
//		}
//
//	}
//}
